package com.data.basic.chapter05;



/** 当需要对头结点进进行判断的时候，就需要头结点dummyHead
 * Created by wangbing on 2018/5/4.
 */


public class Solution1 {
    public ListNode removeElements(ListNode head, int val) {
        while (head!=null&&head.val==val){//删除一开始重复的节点     删除头结点
            ListNode delNode = head;
            head=head.next;
            delNode.next=null;
        }
        if (head==null){
            return null;
        }
        ListNode prev = head;
        while(prev.next!=null){
            if (prev.next.val==val){
                ListNode delNode = prev.next;
                prev.next = delNode.next;
                delNode.next=null;
            }
            else{
                prev = prev.next;
            }
        }
        return head;
    }
}
